using System;
using mojoPortal.Web;

namespace ud_GoldWeatherEtc
{
    public partial class GoldWeatherEtcModule : SiteModuleControl
    {
        private GoldWeatherEtcConfiguration config = new GoldWeatherEtcConfiguration();
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            Load += Page_Load;
        }

        protected virtual void Page_Load(object sender, EventArgs e)
        {
            Page.EnableViewState = true;
            LoadSettings();
            PopulateLabels();
            PopulateControls();
        }

        private void PopulateControls()
        {
            if (config.ShowWeather)
            {
                Weather weather = (Weather)LoadControl("~/GoldWeatherEtc/Controls/Weather.ascx");
                placeHolder.Controls.Add(weather);
            }
            if (config.ShowRate)
            {
                Rate rate = (Rate)LoadControl("~/GoldWeatherEtc/Controls/Rate.ascx");
                placeHolder.Controls.Add(rate);
            }
            if (config.ShowRateCompact)
            {
                RateCompact rateCompact = (RateCompact)LoadControl("~/GoldWeatherEtc/Controls/RateCompact.ascx");
                placeHolder.Controls.Add(rateCompact);
            }
        }

        protected virtual void PopulateLabels()
        {

        }


        protected virtual void LoadSettings()
        {
            pnlContainer.ModuleId = ModuleId;
            config = new GoldWeatherEtcConfiguration(Settings);
            if (!config.CustomCssClass.Equals(string.Empty)) { pnlContainer.CssClass += " " + config.CustomCssClass; }
        }
    }
}
